package org.example.leetCode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Administrator
 */
public class FindRepeatNumber {
    public static void main(String[] args) {
        int[] nums = {2, 4, 2, 6, 7, 9, 1};
        int repeatNumber = findRepeatNumber(nums);
        System.out.println(repeatNumber);
    }

    public static int findRepeatNumber(int[] nums) {
        Set set = new HashSet();
        for (int i = 0; i < nums.length - 1; i++) {
            if (set.add(nums[i])) {
                return nums[i];
            }
        }
        return -1;
    }
}
